package pluginUtils;

import java.util.ArrayList;



public class PolytopeGenerator {

	
	
	
	private ArrayList<Vector4D> theVertices=new ArrayList<Vector4D>();
	
	private static double phi=(1+Math.sqrt(5))/2;
	private static double gamma=-1/phi;
	
	
	public PolytopeGenerator(){
	
		for(int i=0;i<4;i++){
			double[] a={0,0,0,0}; 
			a[i]=1; 
			Vector4D victor=new Vector4D(a); 
			theVertices.add(victor);
			a[i]=-1; 
			victor=new Vector4D(a); 
			theVertices.add(victor); 
		}
		
		for(int i=0;i<16;i++){
			double[] a={0.5,0.5,0.5,0.5};
			int value=i; 
			for(int j=0;j<4;j++){
				if(value%2==0)a[j]=-0.5;
				value=value/2;
			}
			Vector4D victor=new Vector4D(a);
			theVertices.add(victor); 
		}
		// TODO : c'est foireux, faut des permutations paires et puis y a tau et phi...
		double a[]={phi/2,0.5,gamma/2,0};
		
		int permut[][]={{0,1,2,3},{0,2,3,1},{0,3,1,2},{1,0,3,2},{1,2,0,3},
				{1,3,2,0},{2,0,1,3},{2,1,3,0},{2,3,0,1},{3,0,2,1},{3,1,0,2},{3,2,1,0}};
		
		
		for(int i=0;i<2;i++){
			if(i==0)a[0]=phi/2; else a[0]=-phi/2;
			for(int j=0;j<2;j++){
				if(j==0) a[1]=0.5; else a[1]=-0.5;
				for(int k=0;k<2;k++){
					if(k==0) a[2]=gamma/2; else a[2]=-gamma/2;
					for(int m=0;m<12;m++){
						double b[]=new double[4];
						for(int n=0;n<4;n++) b[n]=a[permut[m][n]]; 
						Vector4D victor=new Vector4D(b);
						theVertices.add(victor); 
					}
				}//k
			}//j
		}// i
		
		for(Vector4D tomtom: this.theVertices){
			for(Vector4D nana: this.theVertices){
				if(Vector4D.distance(tomtom, nana)<=1/phi)
					if(!tomtom.equals(nana)) tomtom.addVoisin(nana); 
					
			}//nana
		}// tomtom
		
		
	}
	public ArrayList<Vector4D> getVertices(){return this.theVertices; }
	

	public static void main(String[] args) {
		PolytopeGenerator gege=new PolytopeGenerator();
		/*
		try{
			PrintStream outx=new PrintStream("/tmp/outgeode.txt");
			outx.println("toto"); 
		}
		catch (Exception e){System.out.println(e); }
		*/
		
		System.out.println("done "+gege.theVertices.size());
		for(Vector4D bb:gege.theVertices) System.out.println(bb.nbVoisins()); 
	}
}
